﻿CREATE FUNCTION [dbo].[fn_ProcedureExists]
(
	@Procedure sysname
)
RETURNS BIT
AS
BEGIN
	DECLARE @True  BIT; SET @True  = 1
	DECLARE @False BIT; SET @False = 0
	DECLARE @Object sysname; SET @Object = PARSENAME(@Procedure, 1)
	DECLARE @Schema sysname; SET @Schema = ISNULL(PARSENAME(@Procedure, 2), 'dbo')

	IF EXISTS (
	       SELECT *
	       FROM   sys.objects o
	       WHERE  o.[name] = @Object
	              AND o.[type] = 'P'
				  AND schema_name(o.schema_id) = @Schema	              
	   )
	    RETURN @True

	RETURN @False
END